<template>
  <div>
    <s-table ref="table" :columns="columns" class="user_management_table"  :data="loadData">
      <span slot="created_at" slot-scope="text">
         <span>{{text|formatDate}}</span>
      </span>
      <span slot="status" slot-scope="text, record">
         <span v-if="record.status==0">未下载</span>
        <span v-if="record.status==1">导入成功</span>
        <span v-if="record.status==2">导入失败</span>
      </span>
      <!-- <span slot="file_size"  slot-scope="text, record">
       {{text}}kb
      </span>-->
      <!-- <span slot="status" slot-scope="text, record" v-if="record.status==1">
      已下载
      </span>-->
      <span slot="action" slot-scope="text, record">
        <!-- <a-button
          type="primary"
          @click="download(record.file_url)"
          style="margin-right:10px"
        >下载导入文件</a-button> -->
        <a @click="download(record.file_url)">下载导入文件</a>
      </span>
    </s-table>
  </div>
</template>

<script>
import { STable } from '@/components'
import { importList, takeClassExcel, deleteExport } from '@/api/outgoingfile'
export default {
  name: 'importfile',
  data() {
    return {
      name: 'importfile',
      columns: [
        {
          title: '操作时间',
          dataIndex: 'created_at',
          scopedSlots:{customRender :'created_at'}
        },
        {
          title: '操作类型',
          dataIndex: 'type',
          align:'center'
        },
        
        // {
        //   title: '文件大小',
        //   dataIndex: 'file_size',
        //   align:'center',
        //   customRender(file_size) {
        //     return file_size + 'KB'
        //   }
        // },
        {
          title: '状态',
          dataIndex: 'status',
          align:'center',
          scopedSlots: { customRender: 'status' }
        },
        {
          title: '失败原因',
          dataIndex: 'fail_reason',
          align:'center',
          width:700,
          
        },
        {
          title: '导入数据条数',
          dataIndex: 'count_num',
          align:'center',
          
        },
        {
          title: '操作人',
          dataIndex: 'user_name',
          align:'center',
          
        },
        {
          title: '操作',
          dataIndex: 'action',
          align:'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      queryParam: {
        school_id: this.$store.state.user.school
      },
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return importList(Object.assign(parameter, this.queryParam)).then(res => {
          return res
        })
      },
      selectedRowKeys: [],
      selectedRows: []
    }
  },

  components: {
    STable
  },
  created() {},
  methods: {
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    download(url) {
      window.location.href=url
    },

  }
}
</script>